package com.fulei.device;

import com.bjfl.saleManager.util.LogUtil;
import com.fulei.logic.MotorOperate;

public class MotorDevice
{
  private String deviceType;
  private String comNo;
  private String baudRate;
  
  public MotorDevice(String devType, String com, String brn)
  {
    this.deviceType = devType;
    this.comNo = com;
    this.baudRate = brn;
  }
  
  public int cutPaper(int motorNumber)
  {
    int return_data = 0;
    try
    {
      if ("MOTOR1".equals(this.deviceType))
      {
        MotorOperate.comNo = this.comNo;
        MotorOperate.baudRate = this.baudRate;
        return_data = MotorOperate.CutCard(motorNumber);
      }
    }
    catch (Exception ex)
    {
      LogUtil.writeExceptionLog("机头出票:" + ex.getMessage());
      return_data = -1;
    }
    return return_data;
  }
  
  public int setCardLength(int setCardLength, int motorNumber)
  {
    int return_data = 0;
    try
    {
      if ("MOTOR1".equals(this.deviceType))
      {
        MotorOperate.comNo = this.comNo;
        MotorOperate.baudRate = this.baudRate;
        return_data = MotorOperate.SetCard(motorNumber, setCardLength);
      }
    }
    catch (Exception ex)
    {
      LogUtil.writeExceptionLog("机头出票:" + ex.getMessage());
      return_data = -1;
    }
    return return_data;
  }
  
  public int checkStatus(int motorNumber)
  {
    int return_data = 0;
    try
    {
      if ("MOTOR1".equals(this.deviceType))
      {
        MotorOperate.comNo = this.comNo;
        MotorOperate.baudRate = this.baudRate;
        return_data = MotorOperate.QueryStatus(motorNumber);
      }
    }
    catch (Exception ex)
    {
      LogUtil.writeExceptionLog("机头出票:" + ex.getMessage());
      return_data = -1;
    }
    return return_data;
  }
}
